tg-me.com/python_testit/1161
Create:
Last Update:
Last Update:
🧠 Python-хитрая задача + решение
🖍️ Условие:
У тебя есть список логов (user, login/logout).
Найди тех, кто зашел, но не вышел.
📜 Пример:
logs = [
("alice", "login"),
("bob", "login"),
("alice", "logout"),
("dave", "login"),
("bob", "logout"),
("carol", "login"),
("dave", "logout")
]
________
💻 Решение:
from collections import defaultdict
def find_stuck_users(logs):
counter = defaultdict(int)
for user, action in logs:
if action == "login":
counter[user] += 1
elif action == "logout":
counter[user] -= 1
return sorted([user for user, count in counter.items() if count > 0])
🛠Ответ:
#Python #Challenge #DevPuzzle
@python_job_interview
BY Python tests
Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283
Share with your friend now:
tg-me.com/python_testit/1161